package cn.u313.listener;

import cn.u313.service.JiLuEntryService;
import cn.u313.service.PresentEntryService;
import cn.u313.service.UserEntryService;
import cn.u313.service.YanYuEntryService;
import love.forte.simbot.annotation.Filter;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.annotation.OnPrivate;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.filter.MatchType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 礼品兑换
 */
@Component
public class PresentListen extends BaseListen{

    @Autowired
    PresentEntryService presentEntryService;
    /**
     * 兑换
     * @param groupMsg
     * @param msgSender
     */
    @OnPrivate
    @Filter(value = "兑换",matchType = MatchType.STARTS_WITH)
    public void onPrivateMsg(PrivateMsg groupMsg, MsgSender msgSender) {
        String code = getCode(groupMsg.getMsg());
        String msg ="";
        if(code!=null){
            msg = presentEntryService.buyPresent(code,getQQ(groupMsg));
        }else
            msg =  presentEntryService.getListStr();
        sendPrivateMsg(msgSender,groupMsg,msg);


    }
    @OnGroup
    @Filter(value = "兑换",matchType = MatchType.STARTS_WITH)
    public void duih(GroupMsg groupMsg, MsgSender msgSender) {
        String code = getCode(groupMsg.getMsg());
        String msg ="";
        if(code!=null){
            msg = presentEntryService.buyPresent(code,getQQ(groupMsg));

        }else
            msg =  presentEntryService.getListStr();
        sendMsg(msgSender,groupMsg,msg);


    }
    @OnGroup
    @Filter(value = "待发",matchType = MatchType.STARTS_WITH)
    public void onGroupMsg(GroupMsg groupMsg, MsgSender msgSender) {
        if(!isManager(getQQ(groupMsg)))
            return;
        String code = getCode(groupMsg.getMsg());
        String msg ="";

        if(code!=null){
            msg = presentEntryService.waitPresent(code,getQQ(groupMsg),groupMsg.getMsg());
        }else
            msg =  presentEntryService.waitPresent();
        sendMsg(msgSender,groupMsg,msg);


    }


}
